package com.lyhlmj.oop_client.Frames.WaitFrame;

import com.lyhlmj.oop_client.Utils.GetScreenSize;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.File;

//背景（根）panel
public class RootPanel extends JPanel {
    private Image image;  //设置背景图片

    public RootPanel() {
        try {
            this.image = ImageIO.read(new File("data/oop游戏大厅界面背景.jpg"));
            this.repaint();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        //  得到Frame的大小
        int width = GetScreenSize.getFitSize()[0];
        int height = GetScreenSize.getFitSize()[1];

        //  设置MainFrame背景
        //  读取图片文件
        if (image != null) {
            g.drawImage(image, 0, 0, width, height, null);
        }

        g.setColor(new Color(255, 255, 255, 0));
        g.fillRect(0, 0, width, height);
    }
}
